window.onload = function(){
		$(".nav li").hover(function(){
			$(this).find("ul").show();
		},function(){
			$(this).find("ul").hide();
		});
	
	var reg=/\S/;
	var flag=true;
	$id("uname").onblur=function(){
		if(reg.test(this.value)==false){
			alert("不能为空");
			$id("sub").setAttribute("disabled","disabled");
			flag=false;
		}
	}
	$id("upwd").onblur=function(){
		if(reg.test(this.value)==false){
			alert("不能为空");
			$id("sub").setAttribute("disabled","disabled");
			flag=false;
		}
	}
	$id("repwd").onblur=function(){
		if(reg.test(this.value)==false){
			alert("不能为空");
			$id("sub").setAttribute("disabled","disabled");
			flag=false;
		}
	}
	$id("sub").onclick=function(){
		if(flag==false){
			alert("不能为空");
			$id("sub").setAttribute("disabled","disabled");
		}
	}
	//判断用户是否登录
	var uname = localStorage.getItem("uname");
	if(uname){
		$(".login").html(uname);
	}
	//判断
	$(".form #sub").click(function(){
		$.ajax({
		type:"post",
		url:"unamecheck.php",
		data:{
			uname:$("#uname").val(),
			upwd:$("#upwd").val()
		},
		success:function(res){
			console.log(res)
			if(res=="ok"){
				alert("用户名已存在")
			}else if(res=="no"){
				alert("注册失败")
			}else{
				localStorage.setItem("uname",res);
				location.href = "../login/login.html";
			}
		}
	});
	})
}